package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.ScoreDisplayRulesTeacherService;
import com.wuseguang.springcloud.util.CodeUtil;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 教师关联分数显示规则表 前端控制器
 * </p>
 *
 * @author
 * @since 2020-02-02
 */
@RestController
@RequestMapping("/scoreDisplayRulesTeacher")
public class ScoreDisplayRulesTeacherController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ScoreDisplayRulesTeacherService scoreDisplayRulesTeacherServiceImpl;

    /**
     * 查询教师的分数显示规则
     *
     * @param request
     * @return
     */
    @RequestMapping("/findScoreDisplayRules")
    public Result findScoreDisplayRules(RequestParameterWrapper request) {
        logger.info("查询教师的分数显示规则");
        //教师id
        String teacherId = request.getParam("teacherId");

        List<Map<String, Object>> list = scoreDisplayRulesTeacherServiceImpl.findScoreDisplayRules(teacherId);

        return new Result(list);
    }

    /**
     * 添加教师的显示规则
     *
     * @param request
     * @param scoreDisplayRulesId 规则id
     * @return
     */
    @RequestMapping("/addAndUpdateScoreDisplayRulesTeacher")
    public Result addAndUpdateScoreDisplayRulesTeacher(RequestParameterWrapper request,
                                                       @RequestParam(value = "scoreDisplayRulesId", required = false) Integer scoreDisplayRulesId) {
        logger.info("添加教师的显示规则");

        //教师id
        String teacherId = request.getParam("teacherId");

        //判断规则id不能为空
        if(StringUtils.isEmpty(scoreDisplayRulesId)){
            new Result(CodeUtil.REQUIRED_VALUE_IS_EMPTY.getCode(),CodeUtil.REQUIRED_VALUE_IS_EMPTY.getMsg()+"[规则id为空]");
        }

        return scoreDisplayRulesTeacherServiceImpl.addAndUpdateScoreDisplayRulesTeacher(scoreDisplayRulesId, teacherId);
    }

}

